package com.zj.fx.controller.month;

import com.github.pagehelper.PageInfo;
import com.zj.fx.common.base.BaseController;
import com.zj.fx.common.domain.AjaxResult;
import com.zj.fx.common.domain.ResultTable;
import com.zj.fx.common.support.ConvertUtil;
import com.zj.fx.model.custom.Tablepar;
import com.zj.fx.model.info.InfoProject;
import com.zj.fx.model.info.InfoSupply;
import com.zj.fx.model.month.*;
import com.zj.fx.service.info.InfoProjectService;
import com.zj.fx.service.info.InfoSupplyService;
import com.zj.fx.service.month.*;
import com.zj.fx.shiro.util.ShiroUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.logging.log4j.util.Strings;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 月度分公司审核任务填报Controller
 *
 * @author SQL
 * @ClassName: MonthSupplytaskController
 * @date 2023-06-09 17:15:40
 */
@Api(value = "月度分公司审核任务填报")
@Controller
@RequestMapping("/MonthSubAuditController")
public class MonthSubAuditController extends BaseController {

    private String prefix = "month/monthSubAudit";

    @Autowired
    private MonthSubAuditService monthSubAuditService;

    @Autowired
    private InfoProjectService infoProjectService;

    @Autowired
    private MonthNecessaryService monthNecessaryService;

    @Autowired
    private MonthSupplytaskDtlService monthSupplytaskDtlService;

    @Autowired
    private MonthSupplytaskService monthSupplytaskService;

    @Autowired
    private MonthResultService monthResultService;

    @Autowired
    private MonthResultDtlService monthResultDtlService;

    @Autowired
    private MonthAuditDtlService monthAuditDtlService;

    @Autowired
    private InfoSupplyService infoSupplyService;

    @Autowired
    private MonthAuditSubService monthAuditSubService;

    @Autowired
    private MonthRejectDtlService monthRejectDtlService;


    /**
     * 月度分公司审核任务填报页面展示
     *
     * @param model
     * @return String
     * @author SQL
     */
    @ApiOperation(value = "分页跳转", notes = "分页跳转")
    @GetMapping("/view")
    @RequiresPermissions("gen:monthSubAudit:view")
    public String view(ModelMap model) {
        return prefix + "/list";
    }

    /**
     * list集合
     *
     * @param tablepar
     * @param
     * @return
     */
    //@Log(title = "月度分公司审核任务填报", action = "111")
    @ApiOperation(value = "分页跳转", notes = "分页跳转")
    @GetMapping("/list")
    @RequiresPermissions("gen:monthSubAudit:list")
    @ResponseBody
    public ResultTable list(Tablepar tablepar, MonthSupplytask monthSupplytask) {
        PageInfo<MonthSupplytask> page = monthSubAuditService.list4self(tablepar, monthSupplytask);
        return pageTable(page.getList(), page.getTotal());
    }

    /**
     * 新增跳转
     */
    @ApiOperation(value = "新增跳转", notes = "新增跳转")
    @GetMapping("/add")
    public String add(ModelMap modelMap) {
        return prefix + "/add";
    }

    /**
     * 新增保存
     *
     * @param
     * @return
     */
    //@Log(title = "月度分公司审核任务填报新增", action = "111")
    @ApiOperation(value = "新增", notes = "新增")
    @PostMapping("/add")
    @RequiresPermissions("gen:monthSubAudit:add")
    @ResponseBody
    public AjaxResult add(MonthSupplytask MonthSupplytask) {
        int b = monthSubAuditService.insertSelective(MonthSupplytask);
        if (b > 0) {
            return success();
        } else {
            return error();
        }
    }

    /**
     * 月度分公司审核任务填报删除
     *
     * @param ids
     * @return
     */
    //@Log(title = "月度分公司审核任务填报删除", action = "111")
    @ApiOperation(value = "删除", notes = "删除")
    @DeleteMapping("/remove")
    @RequiresPermissions("gen:monthSubAudit:remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        int b = monthSubAuditService.deleteByPrimaryKey(ids);
        if (b > 0) {
            return success();
        } else {
            return error();
        }
    }


    /**
     * 修改跳转
     *
     * @param id
     * @param
     * @return
     */
    @ApiOperation(value = "修改跳转", notes = "修改跳转")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap map) {
        map.put("MonthSupplytask", monthSubAuditService.selectByPrimaryKey(id));

        return prefix + "/edit";
    }

    /**
     * 修改保存
     */
    //@Log(title = "月度分公司审核任务填报修改", action = "111")
    @ApiOperation(value = "修改保存", notes = "修改保存")
    @RequiresPermissions("gen:monthSubAudit:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MonthSupplytask MonthSupplytask) {
        return toAjax(monthSubAuditService.updateByPrimaryKeySelective(MonthSupplytask));
    }

    /**
     * 审核页面跳转
     */
    @ApiOperation(value = "审核页面跳转", notes = "审核页面跳转")
    @GetMapping("/audit/{id}")
    public String fill(@PathVariable("id") String id, ModelMap modelMap) {
        List<InfoProject> resultList = new ArrayList<>();
        //查询必备项目标签
        //查询标签表头(一级+必备条件项目)
        List<InfoProject> infoProjects = infoProjectService.selectTabTitle();
        modelMap.put("tabTitleList", infoProjects);
        modelMap.put("taskId", id);
        return prefix + "/subaudit";
    }

    /**
     * 分公司审核单条变更并计算实时分数
     *
     * @param
     * @param
     * @return
     */
    @ApiOperation(value = "分公司审核单条变更并计算实时分数", notes = "分公司审核单条变更并计算实时分数")
    @PostMapping("/updateSubAudit")
    @ResponseBody
    public AjaxResult updateSubAudit(@RequestBody MonthSupplytaskDtl monthSupplytaskDtl) {
        //判断审核值与自评价值是否相同，相同的给出提示不做更新
        MonthSupplytaskDtl monthSupplytaskDtl1 = monthSupplytaskDtlService.selectByPrimaryKey(monthSupplytaskDtl.getId());
        if (!MonthConstant.DTL_TACTIC_ISORNOT.equals(monthSupplytaskDtl1.getTactics())) {
            if (Strings.isBlank(monthSupplytaskDtl1.getSubreviewValue())) {
                if (monthSupplytaskDtl1.getSelfValue().equals(monthSupplytaskDtl.getSubreviewValue())) {
                    return AjaxResult.error("审核更正结果与自评价值相同,无需审核更正");
                }
            } else {

            }
        } else {
            if (Strings.isBlank(monthSupplytaskDtl1.getSubreviewValue())) {
                if (monthSupplytaskDtl1.getSelfValue().equals(monthSupplytaskDtl.getSubreviewValue())) {
                    return AjaxResult.error("审核更正结果与自评价值相同,无需审核更正");
                }
            }
        }

        MonthSupplytaskDtl monthSupplytaskDtl4 = monthSubAuditService.updateSubAudit(monthSupplytaskDtl);
        return toAjax(monthSupplytaskDtlService.updateByPrimaryKeySelective(monthSupplytaskDtl4));
    }

    /**
     * 分公司审核提报----页面内，一次提报一个供电所
     *
     * @param
     * @param
     * @return
     */
    @ApiOperation(value = "分公司审核提报", notes = "分公司审核提报")
    @PostMapping("/subauditCommit")
    @ResponseBody
    @Transactional
    public AjaxResult subauditCommit(@RequestBody MonthSupplytask monthSupplytask) {
        //0、关键数据获取及数据初始化
        String id = monthSupplytask.getId();
        String typeOk = "1";
        //一、校验
        //所有五级任务是否有驳回状态下的任务，有则禁止提交
        MonthSupplytaskDtlExample monthSupplytaskDtlExample = new MonthSupplytaskDtlExample();
        monthSupplytaskDtlExample.createCriteria().andFkTaskIdEqualTo(id).andTaskStateEqualTo(MonthConstant.DTL_STATE_ISREJECTED);
        List<MonthSupplytaskDtl> monthSupplytaskDtls = monthSupplytaskDtlService.selectByExample(monthSupplytaskDtlExample);
        if (monthSupplytaskDtls != null && monthSupplytaskDtls.size() > 0) {
            String num = monthSupplytaskDtls.get(0).getNum();
            return AjaxResult.error("指标编号为:" + num + "行数据处于驳回调整中，请等待驳回调整后复核完成再进行提交");
        }

        //二、将对应必备项目、四级、5级任务状态改为”审核完成“，更新审核完成时间
        //2.1 必备
        MonthNecessaryExample monthNecessaryExample1 = new MonthNecessaryExample();
        MonthNecessaryExample.Criteria criteria = monthNecessaryExample1.createCriteria();
        criteria.andFkTaskIdEqualTo(id);
        List<MonthNecessary> monthNecessaries1 = monthNecessaryService.selectByExample(monthNecessaryExample1);
        for (MonthNecessary monthNecessary : monthNecessaries1) {
            //状态置为审核完成
            monthNecessary.setTaskState(MonthConstant.DTL_STATE_AUDITDEPT);
            monthNecessaryService.updateByPrimaryKeySelective(monthNecessary);
        }
        //2.2 明细表四级、五级
        //将该供电所下所有的四级五级明细设置为“责任部门审核中”
        MonthSupplytaskDtlExample monthSupplytaskDtlExample1 = new MonthSupplytaskDtlExample();
        monthSupplytaskDtlExample1.createCriteria().andFkTaskIdEqualTo(id);
        List<MonthSupplytaskDtl> monthSupplytaskDtlList2 = monthSupplytaskDtlService.selectByExample(monthSupplytaskDtlExample1);
        for (MonthSupplytaskDtl monthSupplytaskDtl : monthSupplytaskDtlList2) {
            monthSupplytaskDtl.setTaskState(MonthConstant.DTL_STATE_AUDITDEPT);
            monthSupplytaskDtlService.updateByPrimaryKeySelective(monthSupplytaskDtl);
        }

        //2.3 该供电所月度任务状态置为“责任部门审核中”
        monthSupplytask = monthSupplytaskService.selectByPrimaryKey(id);
        monthSupplytask.setTaskState(MonthConstant.DTL_STATE_AUDITDEPT);
        monthSupplytask.setAuditDate(new Date());//分公司审核完成时间
        monthSupplytaskService.updateByPrimaryKeySelective(monthSupplytask);

        //2.4 生成责任部门针对该供电所的审核明细
        //------------在月度部门审核明细表中生成月度任务部门审核记录
        //------------查询月度任务中的不同部门id，部门名称
        MonthSupplytaskDtl monthSupplytaskDtl = new MonthSupplytaskDtl();
        monthSupplytaskDtl.setFkTaskId(id);
        List<MonthSupplytaskDtl> monthSupplytaskDtlList = monthSupplytaskDtlService.findDistinctDept(monthSupplytaskDtl);
        for (MonthSupplytaskDtl supplytaskDtl : monthSupplytaskDtlList) {
            MonthAuditDtl monthAuditDtl = new MonthAuditDtl();
            monthAuditDtl.setDeptId(supplytaskDtl.getDeptId());
            monthAuditDtl.setDeptName(supplytaskDtl.getDeptName());
            monthAuditDtl.setFkTaskId(id);
            monthAuditDtl.setTaskState(MonthConstant.AUDIT_NOT);
            monthAuditDtl.setSupplyId(monthSupplytask.getSupplyId());
            monthAuditDtl.setSupplyName(monthSupplytask.getSupplyName());
            monthAuditDtl.setTaskMonth(monthSupplytask.getTaskMonth());
            monthAuditDtlService.insertSelective(monthAuditDtl);
        }
        //2.5 查询该分公司下当前任务对应月度是否存在未完成分公司审核的，若不存在，将分公司审核明细中状态改为完成
        List<String> stateList = new ArrayList<>();
        stateList.add("0");
        stateList.add("1");
        stateList.add("2");
        MonthSupplytask monthSupplytask1 = monthSupplytaskService.selectByPrimaryKey(id);
        MonthSupplytaskExample monthSupplytaskExample = new MonthSupplytaskExample();
        monthSupplytaskExample.createCriteria().andFkEvaluationIdEqualTo(monthSupplytask1.getFkEvaluationId())
                .andFkSubcompanyIdEqualTo(ShiroUtils.getSubcompanyId()).andTaskStateIn(stateList);
        List<MonthSupplytask> monthSupplytasks = monthSupplytaskService.selectByExample(monthSupplytaskExample);
        if (!(monthSupplytasks != null && monthSupplytasks.size() > 0)) {
            MonthAuditSubExample monthAuditSubExample = new MonthAuditSubExample();
            monthAuditSubExample.createCriteria().andFkTaskIdEqualTo(monthSupplytask1.getFkEvaluationId()).andFkSubcompanyIdEqualTo(ShiroUtils.getSubcompanyId());
            List<MonthAuditSub> monthAuditSubs = monthAuditSubService.selectByExample(monthAuditSubExample);
            MonthAuditSub monthAuditSub = monthAuditSubs.get(0);
            monthAuditSub.setTaskState(MonthConstant.RESULT_OK);
            monthAuditSubService.updateByPrimaryKeySelective(monthAuditSub);
        }
        return success();
    }

    /**
     * 批量驳回--暂时未使用
     *
     * @param ids
     * @return
     */
    //@Log(title = "月度分公司审核任务填报删除", action = "111")
    @ApiOperation(value = "删除", notes = "删除")
    @DeleteMapping("/reject")
    @ResponseBody
    @Transactional
    public AjaxResult reject(String ids) {
        List<String> lista = ConvertUtil.toListStrArray(ids);
        for (String id : lista) {
            //根据taskid 进行状态变更
            MonthSupplytask monthSupplytask = monthSupplytaskService.selectByPrimaryKey(id);
            if (!MonthConstant.TASK_STATE_ISAUDITING.equals(monthSupplytask.getTaskState())) {
                return AjaxResult.error(monthSupplytask.getTaskMonth() + "--" + monthSupplytask.getSupplyName() + "单据当前状态不允许驳回");
            }
            monthSupplytask.setTaskState(MonthConstant.TASK_STATE_ISREJECTED);
            monthSupplytaskService.updateByPrimaryKeySelective(monthSupplytask);
            //更新审核明细
            MonthSupplytaskDtlExample monthSupplytaskDtlExample = new MonthSupplytaskDtlExample();
            monthSupplytaskDtlExample.createCriteria().andFkTaskIdEqualTo(id);
            List<MonthSupplytaskDtl> monthSupplytaskDtlList = monthSupplytaskDtlService.selectByExample(monthSupplytaskDtlExample);
            for (MonthSupplytaskDtl monthSupplytaskDtl : monthSupplytaskDtlList) {
                monthSupplytaskDtl.setTaskState(MonthConstant.DTL_STATE_ISREJECTED);
                monthSupplytaskDtlService.updateByPrimaryKeySelective(monthSupplytaskDtl);
            }
        }
        return success();
    }

    /**
     * 驳回页面跳转
     */
    @ApiOperation(value = "驳回页面跳转", notes = "驳回页面跳转")
    @GetMapping("/reject/{id}")
    public String reject(@PathVariable("id") String id, ModelMap modelMap) {
        MonthSupplytask monthSupplytask = new MonthSupplytask();
        monthSupplytask.setId(id);
        modelMap.put("MonthSupplytask", monthSupplytask);
        return prefix + "/rejectedit";
    }

    /**
     * 驳回保存
     */
    //@Log(title = "月度分公司审核任务填报修改", action = "111")
    @ApiOperation(value = "驳回保存", notes = "驳回保存")
    @PostMapping("/reject")
    @ResponseBody
    @Transactional
    public AjaxResult rejectSave(@RequestBody MonthSupplytask supplytask) {
        //根据taskid 进行状态变更
        MonthSupplytask monthSupplytask = monthSupplytaskService.selectByPrimaryKey(supplytask.getId());
        if (!MonthConstant.TASK_STATE_ISAUDITING.equals(monthSupplytask.getTaskState())) {
            return AjaxResult.error(monthSupplytask.getTaskMonth() + "--" + monthSupplytask.getSupplyName() + "单据当前状态不允许驳回");
        }
        monthSupplytask.setTaskState(MonthConstant.TASK_STATE_ISREJECTED);
        monthSupplytask.setRejectReason(supplytask.getRejectReason());
        monthSupplytask.setRejectDate(new Date());
        monthSupplytaskService.updateByPrimaryKeySelective(monthSupplytask);
        //更新审核明细
        MonthSupplytaskDtlExample monthSupplytaskDtlExample = new MonthSupplytaskDtlExample();
        monthSupplytaskDtlExample.createCriteria().andFkTaskIdEqualTo(supplytask.getId());
        List<MonthSupplytaskDtl> monthSupplytaskDtlList = monthSupplytaskDtlService.selectByExample(monthSupplytaskDtlExample);
        for (MonthSupplytaskDtl monthSupplytaskDtl : monthSupplytaskDtlList) {
            monthSupplytaskDtl.setTaskState(MonthConstant.DTL_STATE_ISREJECTED);
            monthSupplytaskDtlService.updateByPrimaryKeySelective(monthSupplytaskDtl);
        }

        //在驳回明细中生成驳回记录
        MonthRejectDtl monthRejectDtl = new MonthRejectDtl();
        monthRejectDtl.setFkTaskId(supplytask.getId());
        monthRejectDtl.setRejectDate(new Date());
        monthRejectDtl.setRejectReason(supplytask.getRejectReason());
        monthRejectDtlService.insertSelective(monthRejectDtl);

        return success();
    }

    /**
     * 分公司审核提报----一键提报（剩余的符合条件但未填报的进行一键提报）
     *
     * @param
     * @param
     * @return
     */
    @ApiOperation(value = "分公司审核提报", notes = "分公司审核提报")
    @PostMapping("/allCommit")
    @ResponseBody
    @Transactional
    public AjaxResult allCommit(@RequestBody MonthSupplytask monthSupplytask) {
        int totalNum = 0;
        int finishNum = 0;
        int okNum = 0;

        String taskMonth = monthSupplytask.getTaskMonth();

        //校验1---年月不能为空
        if (Strings.isBlank(taskMonth)){
            return AjaxResult.error("任务年月不能为空，请选择任务年月查询出对应数据再进行一键提报");
        }

        //询当前月份下当前登录账号对应
        MonthAuditSubExample monthAuditSubExample1 = new MonthAuditSubExample();
        monthAuditSubExample1.createCriteria().andTaskMonthEqualTo(taskMonth).andFkSubcompanyIdEqualTo(ShiroUtils.getSubcompanyId());
        List<MonthAuditSub> monthAuditSubs1 = monthAuditSubService.selectByExample(monthAuditSubExample1);
        if (monthAuditSubs1 == null || monthAuditSubs1.size() == 0) {
            return AjaxResult.error("当前所选择月份不存在评价任务，无法提报");
        } else {
            MonthAuditSub monthAuditSub1 = monthAuditSubs1.get(0);
            if (MonthConstant.IS.equals(monthAuditSub1.getTaskState())) {
                return AjaxResult.error("当前所选择月份对应任务已经全部提报完毕，无需重复提报");
            }
        }
        //查询当前月份下当前登录账号对应分公司下属供电所的全部填报单据
        MonthSupplytaskExample monthSupplytaskExample = new MonthSupplytaskExample();
        monthSupplytaskExample.createCriteria().andTaskMonthEqualTo(taskMonth).andFkSubcompanyIdEqualTo(ShiroUtils.getSubcompanyId());
        List<MonthSupplytask> monthSupplytasks = monthSupplytaskService.selectByExample(monthSupplytaskExample);
        if (monthSupplytasks != null && monthSupplytasks.size() == 0) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return AjaxResult.error("当前选择月份不存在单据，无法提报");
        } else {
            totalNum = monthSupplytasks.size();

            Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint();//手动设置设置回滚点

            List<MonthSupplytask> nofilllist = monthSupplytasks.stream().filter(s -> s.getTaskState().equals(MonthConstant.TASK_STATE_NOFILL)).collect(Collectors.toList());
            List<MonthSupplytask> rejectlist = monthSupplytasks.stream().filter(s -> s.getTaskState().equals(MonthConstant.TASK_STATE_ISREJECTED)).collect(Collectors.toList());
            if (nofilllist.size()>0 || rejectlist.size()>0){
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return AjaxResult.error("当前所选择月份存在未完成供电所填报单据或驳回调整中单据，无法一键提报");
            }

            for (MonthSupplytask supplytask : monthSupplytasks) {
//                if (MonthConstant.TASK_STATE_NOFILL.equals(supplytask.getTaskState()) || MonthConstant.TASK_STATE_ISREJECTED.equals(supplytask.getTaskState())) {
//                    //手动提交事务 进行回滚
//                    TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint);
//                    return AjaxResult.error("当前所选择月份存在未完成供电所填报单据或驳回调整中单据，无法一键提报");
//                }
                if (MonthConstant.TASK_STATE_AUDITDEPT.equals(supplytask.getTaskState())) {
                    finishNum++;
                } else {
                    okNum++;
                    //0、关键数据获取及数据初始化
                    String id = supplytask.getId();
                    //一、校验
                    //所有五级任务是否有驳回状态下的任务，有则禁止提交
                    MonthSupplytaskDtlExample monthSupplytaskDtlExample = new MonthSupplytaskDtlExample();
                    monthSupplytaskDtlExample.createCriteria().andFkTaskIdEqualTo(id).andTaskStateEqualTo(MonthConstant.DTL_STATE_ISREJECTED);
                    List<MonthSupplytaskDtl> monthSupplytaskDtls = monthSupplytaskDtlService.selectByExample(monthSupplytaskDtlExample);
                    if (monthSupplytaskDtls != null && monthSupplytaskDtls.size() > 0) {
                        String num = monthSupplytaskDtls.get(0).getNum();
                        return AjaxResult.error("指标编号为:" + num + "行数据处于驳回调整中，请等待驳回调整后复核完成再进行提交");
                    }

                    //二、将对应必备项目、四级、5级任务状态改为”审核完成“，更新审核完成时间
                    //2.1 必备
                    MonthNecessaryExample monthNecessaryExample1 = new MonthNecessaryExample();
                    MonthNecessaryExample.Criteria criteria = monthNecessaryExample1.createCriteria();
                    criteria.andFkTaskIdEqualTo(id);
                    List<MonthNecessary> monthNecessaries1 = monthNecessaryService.selectByExample(monthNecessaryExample1);
                    for (MonthNecessary monthNecessary : monthNecessaries1) {
                        //状态置为审核完成
                        monthNecessary.setTaskState(MonthConstant.DTL_STATE_AUDITDEPT);
                        monthNecessaryService.updateByPrimaryKeySelective(monthNecessary);
                    }
                    //2.2 明细表四级、五级
                    //将该供电所下所有的四级五级明细设置为“责任部门审核中”
                    MonthSupplytaskDtlExample monthSupplytaskDtlExample1 = new MonthSupplytaskDtlExample();
                    monthSupplytaskDtlExample1.createCriteria().andFkTaskIdEqualTo(id);
                    List<MonthSupplytaskDtl> monthSupplytaskDtlList2 = monthSupplytaskDtlService.selectByExample(monthSupplytaskDtlExample1);
                    for (MonthSupplytaskDtl monthSupplytaskDtl : monthSupplytaskDtlList2) {
                        monthSupplytaskDtl.setTaskState(MonthConstant.DTL_STATE_AUDITDEPT);
                        monthSupplytaskDtlService.updateByPrimaryKeySelective(monthSupplytaskDtl);
                    }

                    //2.3 该供电所月度任务状态置为“责任部门审核中”
                    supplytask = monthSupplytaskService.selectByPrimaryKey(id);
                    supplytask.setTaskState(MonthConstant.DTL_STATE_AUDITDEPT);
                    supplytask.setAuditDate(new Date());//分公司审核完成时间
                    monthSupplytaskService.updateByPrimaryKeySelective(supplytask);

                    //2.4 生成责任部门针对该供电所的审核明细
                    //------------在月度部门审核明细表中生成月度任务部门审核记录
                    //------------查询月度任务中的不同部门id，部门名称
                    MonthSupplytaskDtl monthSupplytaskDtl = new MonthSupplytaskDtl();
                    monthSupplytaskDtl.setFkTaskId(id);
                    List<MonthSupplytaskDtl> monthSupplytaskDtlList = monthSupplytaskDtlService.findDistinctDeptAll(monthSupplytaskDtl);
                    for (MonthSupplytaskDtl supplytaskDtl : monthSupplytaskDtlList) {
                        MonthAuditDtl monthAuditDtl = new MonthAuditDtl();
                        monthAuditDtl.setDeptId(supplytaskDtl.getDepartmentId());
                        monthAuditDtl.setDeptName(supplytaskDtl.getDepartmentName());
                        monthAuditDtl.setFkTaskId(id);
                        monthAuditDtl.setSupplyId(supplytask.getSupplyId());
                        monthAuditDtl.setSupplyName(supplytask.getSupplyName());
                        monthAuditDtl.setTaskMonth(supplytask.getTaskMonth());
                        //如果审核指标中该部门没有审核项，状态直接置为完成
                        if ("1".equals(supplytaskDtl.getIsaudit())){
                            monthAuditDtl.setTaskState(MonthConstant.AUDIT_NOT);
                        } else {
                            monthAuditDtl.setTaskState(MonthConstant.AUDIT_FINISH);
                        }
                        monthAuditDtlService.insertSelective(monthAuditDtl);
                    }
                    //2.5 查询该分公司下当前任务对应月度是否存在未完成分公司审核的，若不存在，将分公司审核明细中状态改为完成
                    List<String> stateList = new ArrayList<>();
                    stateList.add("0");
                    stateList.add("1");
                    stateList.add("2");
                    MonthSupplytask monthSupplytask1 = monthSupplytaskService.selectByPrimaryKey(id);
                    MonthSupplytaskExample monthSupplytaskExample1 = new MonthSupplytaskExample();
                    monthSupplytaskExample1.createCriteria().andFkEvaluationIdEqualTo(monthSupplytask1.getFkEvaluationId())
                            .andFkSubcompanyIdEqualTo(ShiroUtils.getSubcompanyId()).andTaskStateIn(stateList);
                    List<MonthSupplytask> monthSupplytasks1 = monthSupplytaskService.selectByExample(monthSupplytaskExample1);
                    if (!(monthSupplytasks1 != null && monthSupplytasks1.size() > 0)) {
                        MonthAuditSubExample monthAuditSubExample = new MonthAuditSubExample();
                        monthAuditSubExample.createCriteria().andFkTaskIdEqualTo(monthSupplytask1.getFkEvaluationId()).andFkSubcompanyIdEqualTo(ShiroUtils.getSubcompanyId());
                        List<MonthAuditSub> monthAuditSubs = monthAuditSubService.selectByExample(monthAuditSubExample);
                        MonthAuditSub monthAuditSub = monthAuditSubs.get(0);
                        monthAuditSub.setTaskState(MonthConstant.RESULT_OK);
                        monthAuditSub.setAuditDate(new Date());
                        monthAuditSubService.updateByPrimaryKeySelective(monthAuditSub);
                    }
                }
            }
        }
        return success(taskMonth+"月评价任务一键提报完成");
    }

    /**
     * 查看提报结果跳转
     */
    @ApiOperation(value = "查看提报结果跳转", notes = "查看提报结果跳转")
    @GetMapping("/viewResult/{id}")
    public String viewResult(@PathVariable("id") String id, ModelMap modelMap) {
        //查询标签表头(一级+必备条件项目)
        List<InfoProject> infoProjects = infoProjectService.selectTabTitle();
        modelMap.put("tabTitleList", infoProjects);
        modelMap.put("taskId", id);
        return prefix + "/viewresult";
    }


}
